package org.jadapter.tests;


import org.jadapter.JAdapter;
import org.jadapter.tests.examples.simple.adapters.IA2IB;
import org.jadapter.tests.examples.simple.adapters.IB2IC;
import org.jadapter.tests.examples.simple.api.IA;
import org.jadapter.tests.examples.simple.api.IB;
import org.jadapter.tests.examples.simple.api.IC;
import org.jadapter.tests.examples.simple.impl.A;

public class TestComponentRegistry extends BaseTestCase {
    
      
    public void testShouldFindAdapterAndAdaptObject() {
        registry.register(IB.class, IA2IB.class, IA.class);
        IB b = registry.adapt(IB.class, new A());
        assertNotNull("A -> B", b);
        
        registry.register(IC.class, IB2IC.class, IB.class);
        IC c = registry.adapt(IC.class, b);
        assertNotNull("B -> C", c);
        
    }
    
    public void testShouldContainOnlyOneAdapter(){
    	JAdapter<String, String> adapter = new JAdapter<String,String>();
    	adapter.setFor(String.class);
    	adapter.setProvides(String.class);
    	adapter.setAdapter(String.class);
    	
    	assertEquals(0, registry.size());    	
    	
    	registry.register(adapter);
    	assertEquals(1, registry.size());    	    	
    }    
}
